#!/bin/bash
# $WORKSPACE
# $JOB_NAME
echo 
echo 
echo Testing MarineMap : revision $MERCURIAL_REVISION
echo
echo

# If env1 exists, it wont be clobbered so we can safely do this
virtualenv env1
cd env1
source bin/activate

# Update lingcod (currently just track trunk)
pip install -e hg+https://marinemap.googlecode.com/hg#egg=marinemap
pip install coverage --upgrade

# Grab the current revision of northcoast
pip install -e hg+https://northcoast-marinemap.googlecode.com/hg@$MERCURIAL_REVISION#egg=northcoast-marinemap
cd src
#hg clone https://northcoast-marinemap.googlecode.com/hg northcoast-marinemap  # -r $MERCURIAL_REVISION
cd northcoast-marinemap

echo `which python`
echo `which coverage`
echo $PATH

if [ -e nc_mlpa/settings_local.py ]
then 
    echo "Using nc_mlpa/settings_local.py"
    coverage run run_tests.py
else
    echo "Creating temp nc_mlpa/settings_local.py"
    echo "MEDIA_ROOT='/tmp/media'" >  nc_mlpa/settings_local.py
    if [ -d /tmp/media ]; then
        rm -rf /tmp/media
    fi
    mkdir /tmp/media
    coverage run run_tests.py
fi

echo 
echo 
echo Building MarineMap docs : revision $MERCURIAL_REVISION
echo
echo
python build_docs.py -d /var/www/northcoast-marinemap-docs 

echo 
echo 
echo Analyzing coverage : revision $MERCURIAL_REVISION
echo
echo
coverage xml --omit /usr/share
cp coverage.xml ../../../
cp TEST-*.xml ../../../
